package com.jitu.bigscreen.test;

import com.jitu.bigscreen.component.LedControlInf;
import com.jitu.bigscreen.model.Date;
import com.jitu.bigscreen.model.TextArea;
import com.jitu.bigscreen.model.*;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.*;

public class MainForm extends JFrame {

    private JPanel contentPane;
    private JTextField textField;
    int retValue = -1;
    byte[] ipToBytes = null;
    private static MainForm frame;
    private JTextField textField_1;
    private JTextField textField_2;
    private JTextField textField_3;
    private JTextField textField_4;
    private JTextField textField_5;
    private JTextField textField_6;
    private JTextField textField_7;
    private JTextField textField_8;
    private JTextField textField_9;
    private JTextField textField_10;
    private JCheckBox chckbxNewCheckBox;
    private JCheckBox checkBox;
    private JCheckBox checkBox_1;
    private JSlider slider, slider_1, slider_2, slider_3;
    private JButton btnNewButton_1;
    private JButton button_7;
    private JButton button_8;
    private JPanel panel_3;
    private JButton button_9;
    private JButton button_10;
    private JButton button_11;
    private JButton button_12;
    private boolean isRefreshTextFlag = false;
    private boolean isRefreshPictureFlag = false;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {

        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {

                    //1、初始化动态库服务
                    LedControlInf.INSTANCE.LV_InitDllEx(1);

                    frame = new MainForm();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public MainForm() {

        setTitle("二次开发demo用例");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 942, 642);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        textField = new JTextField();
        textField.setBounds(92, 10, 328, 30);
        contentPane.add(textField);
        textField.setColumns(10);
        textField.setText("192.168.1.101");

        JLabel lblip = new JLabel("设备IP:");
        lblip.setBounds(28, 17, 54, 15);
        contentPane.add(lblip);

        JPanel panel = new JPanel();
        panel.setToolTipText("");
        panel.setBorder(new TitledBorder(null, "\u5E38\u89C4\u6307\u4EE4\u64CD\u4F5C", TitledBorder.LEADING, TitledBorder.TOP, null, null));
        panel.setBounds(10, 49, 412, 271);
        contentPane.add(panel);
        panel.setLayout(null);

        JButton btnNewButton = new JButton("开屏");
        btnNewButton.setBounds(10, 38, 106, 53);
        panel.add(btnNewButton);
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ipToBytes = (textField.getText() + "\0").getBytes();
                retValue = btOpenScreen_Click(ipToBytes);
                if (retValue == -1) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "开屏失败！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                } else {

                    JOptionPane.showMessageDialog(
                            frame,
                            "开屏成功！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                }
            }
        });

        JButton button = new JButton("关屏");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ipToBytes = (textField.getText() + "\0").getBytes();
                retValue = btCloseScreen_Click(ipToBytes);
                if (retValue == -1) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "关屏失败！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                } else {

                    JOptionPane.showMessageDialog(
                            frame,
                            "关屏成功！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                }
            }
        });
        button.setBounds(10, 113, 106, 53);
        panel.add(button);

        JButton button_1 = new JButton("同步时间");
        button_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                ipToBytes = (textField.getText() + "\0").getBytes();
                retValue = btSynchronizationTime_Click(ipToBytes);
                if (retValue == -1) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "同步时间失败！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                } else {

                    JOptionPane.showMessageDialog(
                            frame,
                            "同步时间成功！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                }
            }
        });
        button_1.setBounds(10, 192, 106, 53);
        panel.add(button_1);

        JButton button_2 = new JButton("开启播放");
        button_2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ipToBytes = (textField.getText() + "\0").getBytes();
                retValue = btStartPlayer_Click(ipToBytes);
                if (retValue == -1) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "开启播放失败！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                } else {

                    JOptionPane.showMessageDialog(
                            frame,
                            "开启播放成功！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                }
            }
        });
        button_2.setBounds(146, 38, 106, 53);
        panel.add(button_2);

        JButton button_3 = new JButton("清理缓存");
        button_3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                ipToBytes = (textField.getText() + "\0").getBytes();
                retValue = btClearDeviceSpace_Click(ipToBytes);
                if (retValue == -1) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "清理缓存失败！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                } else {

                    JOptionPane.showMessageDialog(
                            frame,
                            "清理缓存成功！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                }
            }
        });
        button_3.setBounds(146, 192, 106, 53);
        panel.add(button_3);

        JButton button_4 = new JButton("暂停播放");
        button_4.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                ipToBytes = (textField.getText() + "\0").getBytes();
                retValue = btStopPlayer_Click(ipToBytes);
                if (retValue == -1) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "暂停播放失败！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                } else {

                    JOptionPane.showMessageDialog(
                            frame,
                            "暂停播放成功！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                }
            }
        });
        button_4.setBounds(146, 113, 106, 53);
        panel.add(button_4);

        JButton button_6 = new JButton("重启设备");
        button_6.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                ipToBytes = (textField.getText() + "\0").getBytes();
                retValue = btReStartDevice_Click(ipToBytes);
                if (retValue == -1) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "重启设备失败！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                } else {
                    JOptionPane.showMessageDialog(
                            frame,
                            "重启设备成功！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                }
            }
        });
        button_6.setBounds(296, 38, 106, 53);
        panel.add(button_6);

        JPanel panel_1 = new JPanel();
        panel_1.setBorder(new TitledBorder(null, "\u4EAE\u5EA6\u6307\u4EE4\u8BBE\u7F6E", TitledBorder.LEADING, TitledBorder.TOP, null, null));
        panel_1.setBounds(10, 322, 412, 271);
        contentPane.add(panel_1);
        panel_1.setLayout(null);

        slider = new JSlider(0, 100, 50);
        slider.setBounds(74, 25, 255, 26);
        panel_1.add(slider);
        // 添加刻度改变监听器
        slider.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                System.out.println("当前值: " + slider.getValue());
                textField_3.setText(String.valueOf(slider.getValue()));
            }
        });

        JLabel label = new JLabel("亮度值:");
        label.setBounds(21, 36, 54, 15);
        panel_1.add(label);

        chckbxNewCheckBox = new JCheckBox("");
        chckbxNewCheckBox.setBounds(37, 77, 27, 23);
        panel_1.add(chckbxNewCheckBox);

        textField_1 = new JTextField();
        textField_1.setText("10:00");
        textField_1.setBounds(74, 79, 63, 21);
        panel_1.add(textField_1);
        textField_1.setColumns(10);

        textField_2 = new JTextField();
        textField_2.setText("11:00");
        textField_2.setBounds(147, 79, 66, 21);
        panel_1.add(textField_2);
        textField_2.setColumns(10);

        slider_1 = new JSlider();
        slider_1.setBounds(223, 77, 106, 26);
        panel_1.add(slider_1);

        // 添加刻度改变监听器
        slider_1.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                System.out.println("当前值: " + slider_1.getValue());
                textField_4.setText(String.valueOf(slider_1.getValue()));
            }
        });

        textField_3 = new JTextField();
        textField_3.setText("50");
        textField_3.setColumns(10);
        textField_3.setBounds(339, 25, 66, 21);
        panel_1.add(textField_3);

        textField_4 = new JTextField();
        textField_4.setText("50");
        textField_4.setColumns(10);
        textField_4.setBounds(339, 77, 66, 21);
        panel_1.add(textField_4);

        checkBox = new JCheckBox("");
        checkBox.setBounds(37, 132, 27, 23);
        panel_1.add(checkBox);

        textField_5 = new JTextField();
        textField_5.setText("11:30");
        textField_5.setColumns(10);
        textField_5.setBounds(74, 134, 63, 21);
        panel_1.add(textField_5);

        textField_6 = new JTextField();
        textField_6.setText("13:00");
        textField_6.setColumns(10);
        textField_6.setBounds(147, 134, 66, 21);
        panel_1.add(textField_6);

        slider_2 = new JSlider();
        slider_2.setBounds(223, 132, 106, 26);
        panel_1.add(slider_2);

        // 添加刻度改变监听器
        slider_2.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                System.out.println("当前值: " + slider_2.getValue());
                textField_7.setText(String.valueOf(slider_2.getValue()));
            }
        });

        textField_7 = new JTextField();
        textField_7.setText("50");
        textField_7.setColumns(10);
        textField_7.setBounds(339, 132, 66, 21);
        panel_1.add(textField_7);

        checkBox_1 = new JCheckBox("");
        checkBox_1.setBounds(37, 181, 27, 23);
        panel_1.add(checkBox_1);

        textField_8 = new JTextField();
        textField_8.setText("14:00");
        textField_8.setColumns(10);
        textField_8.setBounds(74, 183, 63, 21);
        panel_1.add(textField_8);

        textField_9 = new JTextField();
        textField_9.setText("15:00");
        textField_9.setColumns(10);
        textField_9.setBounds(147, 183, 66, 21);
        panel_1.add(textField_9);

        slider_3 = new JSlider();
        slider_3.setBounds(223, 181, 106, 26);
        panel_1.add(slider_3);

        // 添加刻度改变监听器
        slider_3.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                System.out.println("当前值: " + slider_3.getValue());
                textField_10.setText(String.valueOf(slider_3.getValue()));
            }
        });

        textField_10 = new JTextField();
        textField_10.setText("50");
        textField_10.setColumns(10);
        textField_10.setBounds(339, 181, 66, 21);
        panel_1.add(textField_10);

        JButton button_5 = new JButton("设置亮度");
        button_5.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                ipToBytes = (textField.getText() + "\0").getBytes();

                //参数格式样例如下：{"period":[{"endTime":"09:00","isSwitchFlag":"1","startTime":"00:00","value":"88"},{"endTime":"12:00","isSwitchFlag":"1","startTime":"10:00","value":"31"}],"value":"44"}

                StringBuilder sbTimingInfo = new StringBuilder("{");
                sbTimingInfo.append("\"period\":");
                sbTimingInfo.append("[");

                if (chckbxNewCheckBox.isSelected()) {
                    sbTimingInfo.append("{");
                    sbTimingInfo.append("\"startTime\":\"" + textField_1.getText() + "\",");
                    sbTimingInfo.append("\"endTime\":\"" + textField_2.getText() + "\",");
                    sbTimingInfo.append("\"isSwitchFlag\":\"1\",");
                    sbTimingInfo.append("\"value\":\"" + textField_4.getText() + "\"");
                    sbTimingInfo.append("}");
                } else {
                    sbTimingInfo.append("{");
                    sbTimingInfo.append("\"startTime\":\"" + textField_1.getText() + "\",");
                    sbTimingInfo.append("\"endTime\":\"" + textField_2.getText() + "\",");
                    sbTimingInfo.append("\"isSwitchFlag\":\"0\",");
                    sbTimingInfo.append("\"value\":\"" + textField_4.getText() + "\"");
                    sbTimingInfo.append("}");
                }

                sbTimingInfo.append(",");

                if (checkBox.isSelected()) {
                    sbTimingInfo.append("{");
                    sbTimingInfo.append("\"startTime\":\"" + textField_5.getText() + "\",");
                    sbTimingInfo.append("\"endTime\":\"" + textField_6.getText() + "\",");
                    sbTimingInfo.append("\"isSwitchFlag\":\"1\",");
                    sbTimingInfo.append("\"value\":\"" + textField_7.getText() + "\"");
                    sbTimingInfo.append("}");
                } else {
                    sbTimingInfo.append("{");
                    sbTimingInfo.append("\"startTime\":\"" + textField_5.getText() + "\",");
                    sbTimingInfo.append("\"endTime\":\"" + textField_6.getText() + "\",");
                    sbTimingInfo.append("\"isSwitchFlag\":\"0\",");
                    sbTimingInfo.append("\"value\":\"" + textField_7.getText() + "\"");
                    sbTimingInfo.append("}");
                }
                sbTimingInfo.append(",");


                if (checkBox_1.isSelected()) {
                    sbTimingInfo.append("{");
                    sbTimingInfo.append("\"startTime\":\"" + textField_8.getText() + "\",");
                    sbTimingInfo.append("\"endTime\":\"" + textField_9.getText() + "\",");
                    sbTimingInfo.append("\"isSwitchFlag\":\"1\",");
                    sbTimingInfo.append("\"value\":\"" + textField_10.getText() + "\"");
                    sbTimingInfo.append("}");
                } else {
                    sbTimingInfo.append("{");
                    sbTimingInfo.append("\"startTime\":\"" + textField_8.getText() + "\",");
                    sbTimingInfo.append("\"endTime\":\"" + textField_9.getText() + "\",");
                    sbTimingInfo.append("\"isSwitchFlag\":\"0\",");
                    sbTimingInfo.append("\"value\":\"" + textField_10.getText() + "\"");
                    sbTimingInfo.append("}");
                }

                sbTimingInfo.append("],");

                sbTimingInfo.append("\"value\":\"" + textField_3.getText() + "\"");

                sbTimingInfo.append("}");

                System.out.println(sbTimingInfo);
                retValue = btSetTimingBrightnessInfo_Click(ipToBytes, sbTimingInfo.toString().getBytes());
                if (retValue == -1) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "亮度设置失败！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                } else {
                    JOptionPane.showMessageDialog(
                            frame,
                            "亮度设置成功！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                }
            }
        });
        button_5.setBounds(299, 212, 106, 53);
        panel_1.add(button_5);

        JPanel panel_2 = new JPanel();
        panel_2.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u5E38\u89C4\u8282\u76EE\u64CD\u4F5C", TitledBorder.LEADING, TitledBorder.TOP, null, null));
        panel_2.setBounds(426, 49, 490, 271);
        contentPane.add(panel_2);
        panel_2.setLayout(null);

        btnNewButton_1 = new JButton("下发轮播节目");
        btnNewButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                isRefreshPictureFlag = false;
                isRefreshTextFlag = false;

                ipToBytes = (textField.getText() + "\0").getBytes();

                try {

                    retValue = btMulProgram_Click(ipToBytes);

                } catch (ParseException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

                if (retValue == -1) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "下发轮播节目失败！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                } else {

                    JOptionPane.showMessageDialog(
                            frame,
                            "下发轮播节目成功！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                }
            }
        });
        btnNewButton_1.setBounds(10, 119, 129, 51);
        panel_2.add(btnNewButton_1);

        button_7 = new JButton("下发定时节目");
        button_7.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                isRefreshPictureFlag = false;
                isRefreshTextFlag = false;

                ipToBytes = (textField.getText() + "\0").getBytes();

                try {

                    retValue = btMulProgramByPeriod_Click(ipToBytes, 30);

                } catch (ParseException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

                if (retValue == -1) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "下发定时节目失败！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                } else {

                    JOptionPane.showMessageDialog(
                            frame,
                            "下发定时节目成功！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                }
            }
        });
        button_7.setBounds(186, 119, 129, 51);
        panel_2.add(button_7);

        button_8 = new JButton("下发插播节目");
        button_8.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                isRefreshPictureFlag = false;
                isRefreshTextFlag = false;

                ipToBytes = (textField.getText() + "\0").getBytes();

                try {

                    retValue = btMulProgramByInsert_Click(ipToBytes);

                } catch (ParseException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

                if (retValue == -1) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "下发插播节目失败！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                } else {

                    JOptionPane.showMessageDialog(
                            frame,
                            "下发插播节目成功！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                }
            }
        });
        button_8.setBounds(352, 119, 128, 51);
        panel_2.add(button_8);

        panel_3 = new JPanel();
        panel_3.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u5C40\u90E8\u5237\u65B0\u6587\u672C\u6216\u56FE\u7247\u8282\u76EE\u64CD\u4F5C", TitledBorder.LEADING, TitledBorder.TOP, null, null));
        panel_3.setBounds(426, 330, 490, 263);
        contentPane.add(panel_3);
        panel_3.setLayout(null);

        button_9 = new JButton("第一步：下发静态文本节目");
        button_9.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                isRefreshPictureFlag = false;
                isRefreshTextFlag = false;
                ipToBytes = (textField.getText() + "\0").getBytes();

                try {

                    retValue = btMulProgramByStaticText_Click(ipToBytes);

                } catch (ParseException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

                if (retValue == -1) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "下发轮播节目失败！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                } else {

                    JOptionPane.showMessageDialog(
                            frame,
                            "下发轮播节目成功！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                }
            }
        });
        button_9.setBounds(10, 79, 190, 51);
        panel_3.add(button_9);

        button_10 = new JButton("第二步：更新静态文本内容");
        button_10.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                new Thread() {
                    @Override
                    public void run() {

                        isRefreshPictureFlag = false;
                        isRefreshTextFlag = true;

                        while (isRefreshTextFlag) {
                            try {

                                ipToBytes = (textField.getText() + "\0").getBytes();
                                Random rd = new Random();

                                String pInfoJson1 = "[{\"areaId\":2,\"text\":\"随机数:" + rd.nextInt(100) + "\",\"fontColor\":\"#ff00ff\",\"refreshTimes\":0,\"base64\":0}]";
                                String pInfoJson2 = "[{\"areaId\":20,\"text\":\"随机数:" + rd.nextInt(100) + "\",\"fontColor\":\"#ff00ff\",\"refreshTimes\":0,\"base64\":0}]";

                                retValue = LedControlInf.INSTANCE.LV_RefreshFixedArea(ipToBytes, pInfoJson1.getBytes());
                                retValue = LedControlInf.INSTANCE.LV_RefreshFixedArea(ipToBytes, pInfoJson2.getBytes());

                                Thread.sleep(5 * 1000);

                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    }

                }.start();

                JOptionPane.showMessageDialog(
                        frame,
                        "提交完成！",
                        "提示：",
                        JOptionPane.INFORMATION_MESSAGE
                );
//				 if(retValue == -1){
//					 JOptionPane.showMessageDialog(
//							    frame ,
//		                        "静态文本内容更新失败！",
//		                        "提示：",
//		                        JOptionPane.INFORMATION_MESSAGE
//		                );
//			        if(retValue != 0){
//			            retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//			            try {
//							System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
//						} catch (UnsupportedEncodingException e1) {
//							// TODO Auto-generated catch block
//							e1.printStackTrace();
//						}
//		            }
//				}
//				else{
//
//					 JOptionPane.showMessageDialog(
//							    frame ,
//		                        "静态文本内容更新成功！",
//		                        "提示：",
//		                        JOptionPane.INFORMATION_MESSAGE
//		                );
//				}
            }
        });
        button_10.setBounds(10, 168, 190, 51);
        panel_3.add(button_10);

        button_11 = new JButton("第一步：下发静态图片节目");
        button_11.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                isRefreshPictureFlag = false;
                isRefreshTextFlag = false;
                ipToBytes = (textField.getText() + "\0").getBytes();

                try {

                    retValue = btMulProgramByStaticPicture_Click(ipToBytes);

                } catch (ParseException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

                if (retValue == -1) {
                    JOptionPane.showMessageDialog(
                            frame,
                            "下发轮播节目失败！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                } else {

                    JOptionPane.showMessageDialog(
                            frame,
                            "下发轮播节目成功！",
                            "提示：",
                            JOptionPane.INFORMATION_MESSAGE
                    );
                }
            }
        });
        button_11.setBounds(278, 79, 190, 51);
        panel_3.add(button_11);

        button_12 = new JButton("第二步：更新静态图片内容");

        button_12.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new Thread() {
                    @Override
                    public void run() {

                        int flag = 0;

                        byte[] errByt = new byte[2048];

                        isRefreshTextFlag = false;
                        isRefreshPictureFlag = true;

                        while (isRefreshPictureFlag) {
                            try {
                                String src = null;
                                String rootPath = System.getProperty("user.dir") + "\\resources\\";
                                String src0 = rootPath.replace("\\", "\\\\") + "10.bmp";
                                String src1 = rootPath.replace("\\", "\\\\") + "11.bmp";
                                if (flag % 2 != 0) {
                                    src = src0;
                                } else {
                                    src = src1;
                                }

                                ipToBytes = (textField.getText() + "\0").getBytes();

                                String pInfoJson1 = "[{\"info\":[{\"areaId\":0,\"src\":[\"" + src + "\"]}],\"pageId\":1}]";

                                retValue = LedControlInf.INSTANCE.LV_RefreshPictureArea(ipToBytes, pInfoJson1.getBytes());
                                if (retValue != 0) {
                                    retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
                                    System.out.println(new String(new String(errByt).getBytes("ISO8859_1"), "UTF-8"));
                                }
                                flag++;
                                Thread.sleep(5 * 1000);

                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            } catch (UnsupportedEncodingException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }

                }.start();

                JOptionPane.showMessageDialog(
                        frame,
                        "提交完成！",
                        "提示：",
                        JOptionPane.INFORMATION_MESSAGE
                );

            }
        });
        button_12.setBounds(278, 168, 190, 51);
        panel_3.add(button_12);
    }

    //设置亮度指令
    private static int btSetTimingBrightnessInfo_Click(byte[] pIp, byte[] pTimingInfo) {
        int retValue = 0;
        try {
            retValue = LedControlInf.INSTANCE.LV_SetTimingBrightnessInfo(pIp, pTimingInfo);
            System.out.println(retValue == 0 ? "亮度设置成功" : "亮度设置失败");
        } catch (Exception e) {
            // TODO: handle exception
        } finally {
            return retValue;
        }
    }

    //清理缓存指令
    private static int btClearDeviceSpace_Click(byte[] pIp) {
        int retValue = 0;
        try {
            retValue = LedControlInf.INSTANCE.LV_ClearDeviceSpace(pIp);
            System.out.println(retValue == 0 ? "清理缓存成功" : "清理缓存失败");
        } catch (Exception e) {
            // TODO: handle exception
        } finally {
            return retValue;
        }
    }

    //停止播放指令
    private static int btStopPlayer_Click(byte[] pIp) {
        int retValue = 0;
        try {
            retValue = LedControlInf.INSTANCE.LV_StopPlay(pIp);
            System.out.println(retValue == 0 ? "停止播放成功" : "停止播放失败");
        } catch (Exception e) {
            // TODO: handle exception
        } finally {
            return retValue;
        }
    }

    //开启播放指令
    private static int btStartPlayer_Click(byte[] pIp) {
        int retValue = 0;
        try {
            retValue = LedControlInf.INSTANCE.LV_RunPlay(pIp);
            System.out.println(retValue == 0 ? "开启播放成功" : "开启播放失败");
        } catch (Exception e) {
            // TODO: handle exception
        } finally {
            return retValue;
        }
    }

    //重启设备指令
    private static int btReStartDevice_Click(byte[] pIp) {
        int retValue = 0;
        try {
            retValue = LedControlInf.INSTANCE.LV_RestartDevice(pIp);
            System.out.println(retValue == 0 ? "重启设备成功" : "重启设备失败");
        } catch (Exception e) {
            // TODO: handle exception
        } finally {
            return retValue;
        }
    }

    //关屏指令
    private static int btCloseScreen_Click(byte[] pIp) {
        int retValue = 0;
        try {
            retValue = LedControlInf.INSTANCE.LV_SwitchLed(pIp, 0);
            System.out.println(retValue == 0 ? "关屏成功" : "关屏失败");
        } catch (Exception e) {
            // TODO: handle exception
        } finally {
            return retValue;
        }
    }

    //开屏指令
    private static int btOpenScreen_Click(byte[] pIp) {
        int retValue = 0;
        try {
            retValue = LedControlInf.INSTANCE.LV_SwitchLed(pIp, 1);
            System.out.println(retValue == 0 ? "开屏成功" : "开屏失败");
        } catch (Exception e) {
            // TODO: handle exception
        } finally {
            return retValue;
        }
    }

    //同步时间指令
    private static int btSynchronizationTime_Click(byte[] pIp) {
        int retValue = 0;
        try {
            retValue = LedControlInf.INSTANCE.LV_SynchronizationTime(pIp);
            System.out.println(retValue == 0 ? "同步时间成功" : "同步时间失败");
        } catch (Exception e) {
            // TODO: handle exception
        } finally {
            return retValue;
        }
    }

    //多节目多页面-发送轮播节目
    private static int btMulProgram_Click(byte[] iptobytes) throws ParseException {
        /**
         发布轮播节目的流程：

         1、定义一个屏幕，即添加一个屏幕;
         2、定义节目的名称与ID;
         3、定义节目页面，即添加节目页面;
         4、添加显示区域（如文本、图片、视频等），即为页面添加多个显示区域;
         5、发送节目内容到设备;
         6、发送节目计划到设备，进行刷新显示;
         **/


        //1、定义屏幕，即添加一个屏幕
        String screenName1 = "test1";

        //2、定义节目ID及节目名称
        String pProgramId = "13";
        String pProgramName = "13";

        byte[] pProgramIdToBytes = (pProgramId + "\0").getBytes();
        byte[] pProgramNameToBytes = (pProgramName + "\0").getBytes();
        byte[] screenNameToBytes = (screenName1 + "\0").getBytes();

        String rootPath = System.getProperty("user.dir") + "\\resources\\";

        byte[] errByt = new byte[2048];
        int retValue = 0;

        try {

            retValue = LedControlInf.INSTANCE.LV_ClearProgram(screenNameToBytes);
            System.out.println("LV_ClearProgram = " + retValue);

            Random rd = new Random();
            int pageId = rd.nextInt(100);
            //直行
            String src1 = rootPath + "88.jpg";

            //*****************3、添加节目页面***********************************************************************
            Page page = new Page();
            page.setPageId(pageId);
            page.setResolution("1920X1080");
            page.setBgColor("#000000");
            page.setBgImg("");
            page.setEqType("Q5");
            page.setPageTime(10);
            UUID uuid = UUID.randomUUID();
            page.setGuid(uuid.toString());

            //对象转为Json
            ObjectMapper mapper = new ObjectMapper();
            String pPageJson = mapper.writeValueAsString(page);
            System.out.println(pPageJson);

            byte[] pageJsontoBytes = pPageJson.getBytes();
            int resurt1 = LedControlInf.INSTANCE.LV_AddPageToProgram(screenNameToBytes, pProgramIdToBytes, pageJsontoBytes);

//         byte[] errByt = new byte[2048];
//         retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//
//         System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt1 == 0 ? "添加节目页面成功" : "添加节目页面失败");

            //*****************4、在节目页面上添加对应的显示区域*********************************************************

            //图片区域
            PictureArea a = new PictureArea();
            a.setId(1);
            a.setType(1);
            a.setBorderEffect(0);
            a.setBorderSW(0);
            a.setBorderSpeed(0);
            a.setBorderType(0);
            a.setLeft(0);
            a.setTop(0);
            a.setWidth(128);
            a.setHeight(128);
            a.setPauseTime(5);
            a.setRotation(0);
            a.setSiderType(6);
            List<SrcGroup> lsg = new ArrayList<SrcGroup>();
            a.setSrcGroup(lsg);

            SrcGroup s = new SrcGroup();
            s.setId(1);
            s.setSrc(src1);
            a.getSrcGroup().add(s);

            SrcGroup s1 = new SrcGroup();
            s1.setId(2);
            src1 = rootPath + "83.jpg";
            s1.setSrc(src1);
            a.getSrcGroup().add(s1);
            a.setzIndex(0);

            //对象转为Json
            String ajson = mapper.writeValueAsString(a);

            System.out.println(ajson);

            byte[] ajsontobytes = ajson.getBytes();
//         int resurt2 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, ajsontobytes);
            int resurt2 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes, pProgramIdToBytes, pageId, ajsontobytes);
//         retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//         System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt2 == 0 ? "添加图片区域成功" : "添加图片区域失败");


            //视频区域
            VideoArea videoArea = new VideoArea();
            videoArea.setId(3);
            videoArea.setType(0);
            videoArea.setBorderEffect(1);
            videoArea.setBorderSW(1);
            videoArea.setBorderSpeed(1);
            videoArea.setBorderType(9);
            videoArea.setLeft(0);
            videoArea.setTop(256);
            videoArea.setWidth(288);
            videoArea.setHeight(96);
            videoArea.setPauseTime(5);
            videoArea.setRotation(0);
            videoArea.setSiderType(6);
            List<SrcGroup> lsgVideoArea = new ArrayList<SrcGroup>();
            videoArea.setSrcGroup(lsgVideoArea);

            src1 = rootPath + "21.mp4";
            SrcGroup sVideoArea = new SrcGroup();
            sVideoArea.setId(1);
            sVideoArea.setSrc(src1);
            videoArea.getSrcGroup().add(sVideoArea);

            SrcGroup sVideoArea1 = new SrcGroup();
            sVideoArea1.setId(2);
            src1 = rootPath + "23.mp4";
            sVideoArea1.setSrc(src1);
            videoArea.getSrcGroup().add(sVideoArea1);
            videoArea.setzIndex(0);

            //对象转为Json
            String vjson = mapper.writeValueAsString(videoArea);

            System.out.println(vjson);

            byte[] vjsontobytes = vjson.getBytes();
//         int resurt3 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, vjsontobytes);
            int resurt3 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes, pProgramIdToBytes, pageId, vjsontobytes);
//         retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//         System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt3 == 0 ? "添加视频区域成功" : "添加视频区域失败");


            //文本区域
            TextArea textArea = new TextArea();
            //id
            textArea.setId(2);
            //type Int 区域素材类型，字幕对应的类型为:2
            textArea.setType(2);
            //borderSW Int 区域边框开关 1:开 0:关
            textArea.setBorderSW(0);
            //borderEffect Int 区域边框特效 0:静止 1:旋转 2:闪烁
            textArea.setBorderEffect(0);
            //颜色特效 0:无 1:水平渐变 2:垂直渐变 3:斜角渐变
            textArea.setColorEffect(0);
            //borderSpeed int 区域边框速度 0~4
            textArea.setBorderSpeed(0);
            //borderType Int 区域边框类型 0~9 详见附录
            textArea.setBorderType(0);
            //left Int 区域 x 坐标点
            textArea.setLeft(256);
            //top Int 区域 y 坐标点
            textArea.setTop(0);
            //width Int 区域宽度
            textArea.setWidth(256);
            //height Int 区域高度
            textArea.setHeight(64);
            //background String 背景颜色,如:”#000000”,16 进制的 RRGGBB
            textArea.setBackground("#000000");
            //fontColor String 文字颜色, 如:”#ffffff”,16 进制的 RRGGBB
            textArea.setFontColor("#00ff00");
            //fontFamily String 文字字体,如”宋体”
            textArea.setFontFamily("宋体");
            //fontSize Int 字体大小 12~128 ,单位 px
            textArea.setFontSize(48);
            //italic Int 是否斜体 1:是 0:否
            textArea.setItalic(0);
            // bold Int 是否粗体 1:是 0:否
            textArea.setBold(1);
            //textLine Int 文字线 0:无 1:下划线 2:删除线
            textArea.setTextLine(0);
            //lineHeight Int 行间距,多行时有效
            textArea.setLineHeight(5);
            //pauseTime Int 停留时间,当字幕为向左向右平移时的停留时间,连续移 动无效 0~255
            textArea.setPauseTime(5);
            //scrollSpeed Int 字幕滚动速度 0~14
            textArea.setScrollSpeed(2);
            //siderType Int 滚动方式 0:静止 1:向左移动 2:向左连续移动 3:向右移动 4:向右连续移动
            textArea.setSiderType(2);
            //textAlign Int 对齐方式 0:左,1:中间 2:右
            textArea.setTextAlign(0);

            textArea.setTextTop(0);

            String strTextInfo = "AAAA灵信视觉二次开发动态库文本发送";
//         String base64Sign = base64.encodeToString(strTextInfo.getBytes("UTF-8"));
            textArea.setText(strTextInfo);
            //textShow Int 字幕显示方式 1:单行 0:多行
            textArea.setTextShow(1);
            //zIndex int 层级
            textArea.setzIndex(0);

            //对象转为Json
            String tjson = mapper.writeValueAsString(textArea);

            System.out.println(tjson);

            byte[] tjsontobytes = tjson.getBytes();
//        int resurt4 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, tjsontobytes);
            int resurt4 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes, pProgramIdToBytes, pageId, tjsontobytes);
//        retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//        System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt4 == 0 ? "添加文本区域成功" : "添加文本区域失败");

            //*****************5、发送节目内容*********************************************************

            //节目发送
//         retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(iptobytes);

            retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(screenNameToBytes, iptobytes, pProgramIdToBytes, pProgramNameToBytes, new byte[0]);
//         if(retValue != 0){
//            retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//            System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
//         }
            System.out.println(retValue == 0 ? "节目内容发送成功" : "节目内容发送失败");

            //*****************6、 发送节目计划,执行播放节目指令 *********************************************************
            String pDefResVideoFile = "\0";

//         MulProgram mulProgram = new MulProgram();


            List<ProgramPlan> lsProgram = new ArrayList<ProgramPlan>();

            ProgramPlan programPlan = new ProgramPlan();
            programPlan.setCreateDate(String.valueOf(new java.util.Date().getTime()));
            programPlan.setProgramId(pProgramId);
            programPlan.setProgramName(pProgramName);
            programPlan.setProgramType(1);//1标识为轮播节目
            programPlan.setUpdateDate(String.valueOf(new java.util.Date().getTime()));

            List<Date> lsDate = new ArrayList<Date>();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            date.setDateStart(formatter.parse("2020-03-30").getTime());
            date.setDateEnd(formatter.parse("2020-04-30").getTime());
            lsDate.add(date);
            programPlan.setDate(lsDate);

            List<Time> lsTime = new ArrayList<Time>();
            Time time = new Time();
            time.setTimeStart("07:59:59");
            time.setTimeEnd("21:59:59");
            lsTime.add(time);
            programPlan.setTime(lsTime);

            programPlan.setIsDefault(1);
            List lsPlanWeekDay = new ArrayList();
            for (int i = 0; i < 7; i++) {
                lsPlanWeekDay.add(1);
            }
            programPlan.setPlanWeekDay(lsPlanWeekDay);
            lsProgram.add(programPlan);

//         mulProgram.setProgram(lsProgram);

            //对象转为Json
            String pPlanJsonData = mapper.writeValueAsString(lsProgram);
            System.out.println(pPlanJsonData);
            byte[] pPlanDatatobytes = pPlanJsonData.getBytes();

            if (retValue == 0) {
                retValue = LedControlInf.INSTANCE.LV_SendProgramPlan(iptobytes, pPlanDatatobytes, pDefResVideoFile.getBytes());
                System.out.println(retValue == 0 ? "节目更新计划发送成功" : "节目更新发送失败");
            }

            int retValue1 = LedControlInf.INSTANCE.LV_ProgramSendProcessEnd();
            System.out.println(retValue1 == 0 ? "节目缓存清理成功" : "节目缓存清理失败");
        } catch (JsonGenerationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            retValue = -1;
        } catch (JsonMappingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            retValue = -1;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            retValue = -1;
        }
        return retValue;
    }

    //多节目多页面-发送定时节目
    private static int btMulProgramByPeriod_Click(byte[] iptobytes, int intStepTimeValue) throws ParseException {
        /**
         发布定时节目的流程：

         1、定义一个屏幕，即添加一个屏幕;
         2、定义节目的名称与ID;
         3、定义节目页面，即添加节目页面;
         4、添加显示区域（如文本、图片、视频等），即为页面添加多个显示区域;
         5、发送节目内容到设备;
         6、设置定时节目的日期范围与时间范围，并发送节目计划到设备，进行刷新显示;
         **/

        //1、定义屏幕，即添加一个屏幕
        String screenName1 = "test1";

        //2、定义节目ID及节目名称
        String pProgramId = "14";
        String pProgramName = "14";

        byte[] pProgramIdToBytes = (pProgramId + "\0").getBytes();
        byte[] pProgramNameToBytes = (pProgramName + "\0").getBytes();
        byte[] screenNameToBytes = (screenName1 + "\0").getBytes();

        String rootPath = System.getProperty("user.dir") + "\\resources\\";

        byte[] errByt = new byte[2048];
        int retValue = 0;

        try {

            retValue = LedControlInf.INSTANCE.LV_ClearProgram(screenNameToBytes);
            System.out.println("LV_ClearProgram = " + retValue);

            Random rd = new Random();
            int pageId = rd.nextInt(100);
            //直行
            String src1 = rootPath + "10.bmp";

            //*****************3、添加节目页面***********************************************************************
            Page page = new Page();
            page.setPageId(pageId);
            page.setResolution("1920X1080");
            page.setBgColor("#000000");
            page.setBgImg("");
            page.setEqType("Q5");
            page.setPageTime(10);
            UUID uuid = UUID.randomUUID();
            page.setGuid(uuid.toString());

            //对象转为Json
            ObjectMapper mapper = new ObjectMapper();
            String pPageJson = mapper.writeValueAsString(page);
            System.out.println(pPageJson);

            byte[] pageJsontoBytes = pPageJson.getBytes();
            int resurt1 = LedControlInf.INSTANCE.LV_AddPageToProgram(screenNameToBytes, pProgramIdToBytes, pageJsontoBytes);

//         byte[] errByt = new byte[2048];
//         retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//
//         System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt1 == 0 ? "添加节目页面成功" : "添加节目页面失败");

            //*****************4、在节目页面上添加对应的显示区域*********************************************************

            //图片区域
            PictureArea a = new PictureArea();
            a.setId(1);
            a.setType(1);
            a.setBorderEffect(0);
            a.setBorderSW(0);
            a.setBorderSpeed(0);
            a.setBorderType(0);
            a.setLeft(0);
            a.setTop(0);
            a.setWidth(256);
            a.setHeight(192);
            a.setPauseTime(5);
            a.setRotation(0);
            a.setSiderType(6);
            List<SrcGroup> lsg = new ArrayList<SrcGroup>();
            a.setSrcGroup(lsg);

            SrcGroup s = new SrcGroup();
            s.setId(1);
            s.setSrc(src1);
            a.getSrcGroup().add(s);

            SrcGroup s1 = new SrcGroup();
            s1.setId(2);
            src1 = rootPath + "11.bmp";
            s1.setSrc(src1);
            a.getSrcGroup().add(s1);
            a.setzIndex(0);

            //对象转为Json
            String ajson = mapper.writeValueAsString(a);

            System.out.println(ajson);

            byte[] ajsontobytes = ajson.getBytes();
//         int resurt2 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, ajsontobytes);
            int resurt2 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes, pProgramIdToBytes, pageId, ajsontobytes);
//         retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//         System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt2 == 0 ? "添加图片区域成功" : "添加图片区域失败");


            //视频区域
            VideoArea videoArea = new VideoArea();
            videoArea.setId(3);
            videoArea.setType(0);
            videoArea.setBorderEffect(1);
            videoArea.setBorderSW(1);
            videoArea.setBorderSpeed(1);
            videoArea.setBorderType(9);
            videoArea.setLeft(0);
            videoArea.setTop(256);
            videoArea.setWidth(288);
            videoArea.setHeight(96);
            videoArea.setPauseTime(5);
            videoArea.setRotation(0);
            videoArea.setSiderType(6);
            List<SrcGroup> lsgVideoArea = new ArrayList<SrcGroup>();
            videoArea.setSrcGroup(lsgVideoArea);

            src1 = rootPath + "21.mp4";
            SrcGroup sVideoArea = new SrcGroup();
            sVideoArea.setId(1);
            sVideoArea.setSrc(src1);
            videoArea.getSrcGroup().add(sVideoArea);

            SrcGroup sVideoArea1 = new SrcGroup();
            sVideoArea1.setId(2);
            src1 = rootPath + "23.mp4";
            sVideoArea1.setSrc(src1);
            videoArea.getSrcGroup().add(sVideoArea1);
            videoArea.setzIndex(0);

            //对象转为Json
            String vjson = mapper.writeValueAsString(videoArea);

            System.out.println(vjson);

            byte[] vjsontobytes = vjson.getBytes();
//         int resurt3 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, vjsontobytes);
            int resurt3 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes, pProgramIdToBytes, pageId, vjsontobytes);
//         retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//         System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt3 == 0 ? "添加视频区域成功" : "添加视频区域失败");


            //文本区域
            TextArea textArea = new TextArea();
            //id
            textArea.setId(2);
            //type Int 区域素材类型，字幕对应的类型为:2
            textArea.setType(2);
            //borderSW Int 区域边框开关 1:开 0:关
            textArea.setBorderSW(0);
            //borderEffect Int 区域边框特效 0:静止 1:旋转 2:闪烁
            textArea.setBorderEffect(0);
            //颜色特效 0:无 1:水平渐变 2:垂直渐变 3:斜角渐变
            textArea.setColorEffect(0);
            //borderSpeed int 区域边框速度 0~4
            textArea.setBorderSpeed(0);
            //borderType Int 区域边框类型 0~9 详见附录
            textArea.setBorderType(0);
            //left Int 区域 x 坐标点
            textArea.setLeft(256);
            //top Int 区域 y 坐标点
            textArea.setTop(0);
            //width Int 区域宽度
            textArea.setWidth(256);
            //height Int 区域高度
            textArea.setHeight(64);
            //background String 背景颜色,如:”#000000”,16 进制的 RRGGBB
            textArea.setBackground("#000000");
            //fontColor String 文字颜色, 如:”#ffffff”,16 进制的 RRGGBB
            textArea.setFontColor("#00ff00");
            //fontFamily String 文字字体,如”宋体”
            textArea.setFontFamily("宋体");
            //fontSize Int 字体大小 12~128 ,单位 px
            textArea.setFontSize(48);
            //italic Int 是否斜体 1:是 0:否
            textArea.setItalic(0);
            // bold Int 是否粗体 1:是 0:否
            textArea.setBold(1);
            //textLine Int 文字线 0:无 1:下划线 2:删除线
            textArea.setTextLine(0);
            //lineHeight Int 行间距,多行时有效
            textArea.setLineHeight(5);
            //pauseTime Int 停留时间,当字幕为向左向右平移时的停留时间,连续移 动无效 0~255
            textArea.setPauseTime(5);
            //scrollSpeed Int 字幕滚动速度 0~14
            textArea.setScrollSpeed(2);
            //siderType Int 滚动方式 0:静止 1:向左移动 2:向左连续移动 3:向右移动 4:向右连续移动
            textArea.setSiderType(2);
            //textAlign Int 对齐方式 0:左,1:中间 2:右
            textArea.setTextAlign(0);

            textArea.setTextTop(0);

            String strTextInfo = "AAAA灵信视觉二次开发动态库文本发送";
//         String base64Sign = base64.encodeToString(strTextInfo.getBytes("UTF-8"));
            textArea.setText(strTextInfo);
            //textShow Int 字幕显示方式 1:单行 0:多行
            textArea.setTextShow(1);
            //zIndex int 层级
            textArea.setzIndex(0);

            //对象转为Json
            String tjson = mapper.writeValueAsString(textArea);

            System.out.println(tjson);

            byte[] tjsontobytes = tjson.getBytes();
//        int resurt4 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, tjsontobytes);
            int resurt4 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes, pProgramIdToBytes, pageId, tjsontobytes);
//        retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//        System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt4 == 0 ? "添加文本区域成功" : "添加文本区域失败");

            //*****************5、 发送节目内容*********************************************************

            //节目发送
//         retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(iptobytes);

            retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(screenNameToBytes, iptobytes, pProgramIdToBytes, pProgramNameToBytes, new byte[0]);
//         if(retValue != 0){
//            retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//            System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
//         }
            System.out.println(retValue == 0 ? "节目内容发送成功" : "节目内容发送失败");

            //*****************6、 发送节目计划,执行播放节目指令 *********************************************************
            String pDefResVideoFile = "\0";

//         MulProgram mulProgram = new MulProgram();


            List<ProgramPlan> lsProgram = new ArrayList<ProgramPlan>();

            ProgramPlan programPlan = new ProgramPlan();
            programPlan.setCreateDate(String.valueOf(new java.util.Date().getTime()));
            programPlan.setProgramId(pProgramId);
            programPlan.setProgramName(pProgramName);
            programPlan.setProgramType(3);//1:轮播节目(该类型节目最多只能1个) 2:插播节目 3:定时节目
            programPlan.setUpdateDate(String.valueOf(new java.util.Date().getTime()));


            //设置插播的日期范围与时间范围
            List<Date> lsDate = new ArrayList<Date>();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

            Date date = new Date();
            date.setDateStart(formatter.parse("2020-03-30").getTime());
            date.setDateEnd(formatter.parse("2021-03-30").getTime());
            lsDate.add(date);
            programPlan.setDate(lsDate);

            List<Time> lsTime = new ArrayList<Time>();
            Time time = new Time();
            SimpleDateFormat formatterTime = new SimpleDateFormat("HH:mm:ss");
            time.setTimeStart(formatterTime.format(Calendar.getInstance().getTime()));
            Calendar cal = Calendar.getInstance();
            cal.setTime(Calendar.getInstance().getTime());
            cal.add(Calendar.MINUTE, intStepTimeValue);
            time.setTimeEnd(formatterTime.format(cal.getTime()));

//         time.setTimeStart("15:40:59");
//         time.setTimeEnd("15:59:59");
            lsTime.add(time);
            programPlan.setTime(lsTime);

            programPlan.setIsDefault(0);
            List lsPlanWeekDay = new ArrayList();
            for (int i = 0; i < 7; i++) {
                lsPlanWeekDay.add(1);
            }
            programPlan.setPlanWeekDay(lsPlanWeekDay);
            lsProgram.add(programPlan);

//         mulProgram.setProgram(lsProgram);

            //对象转为Json
            String pPlanJsonData = mapper.writeValueAsString(lsProgram);
            System.out.println(pPlanJsonData);
            byte[] pPlanDatatobytes = pPlanJsonData.getBytes();

            if (retValue == 0) {
                retValue = LedControlInf.INSTANCE.LV_SendProgramPlan(iptobytes, pPlanDatatobytes, pDefResVideoFile.getBytes());
                System.out.println(retValue == 0 ? "节目更新计划发送成功" : "节目更新发送失败");
            }


            int retValue1 = LedControlInf.INSTANCE.LV_ProgramSendProcessEnd();
            System.out.println(retValue1 == 0 ? "节目缓存清理成功" : "节目缓存清理失败");
        } catch (JsonGenerationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            retValue = -1;
        } catch (JsonMappingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            retValue = -1;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            retValue = -1;
        }
        return retValue;
    }

    //多节目多页面-发送插播节目
    private static int btMulProgramByInsert_Click(byte[] iptobytes) throws ParseException {

        /**
         发布插播节目的流程：

         1、定义一个屏幕，即添加一个屏幕;
         2、定义节目的名称与ID;
         3、定义节目页面，即添加节目页面;
         4、添加显示区域（如文本、图片、视频等），即为页面添加多个显示区域;
         5、发送节目内容到设备;
         6、设置插播的日期范围与时间范围，发送节目计划到设备，进行刷新显示;
         **/
        //1、定义屏幕，即添加一个屏幕
        String screenName1 = "test1";

        //2、定义节目ID及节目名称
        String pProgramId = "15";
        String pProgramName = "15";

        byte[] pProgramIdToBytes = (pProgramId + "\0").getBytes();
        byte[] pProgramNameToBytes = (pProgramName + "\0").getBytes();
        byte[] screenNameToBytes = (screenName1 + "\0").getBytes();

        String rootPath = System.getProperty("user.dir") + "\\resources\\";

        byte[] errByt = new byte[2048];
        int retValue = 0;
        try {

            retValue = LedControlInf.INSTANCE.LV_ClearProgram(screenNameToBytes);
            System.out.println("LV_ClearProgram = " + retValue);

            Random rd = new Random();
            int pageId = rd.nextInt(100);
            //直行
            String src1 = rootPath + "11.bmp";

            //*****************3、 添加节目页面***********************************************************************
            Page page = new Page();
            page.setPageId(pageId);
            page.setResolution("1920X1080");
            page.setBgColor("#000000");
            page.setBgImg("");
            page.setEqType("Q5");
            page.setPageTime(10);
            UUID uuid = UUID.randomUUID();
            page.setGuid(uuid.toString());

            //对象转为Json
            ObjectMapper mapper = new ObjectMapper();
            String pPageJson = mapper.writeValueAsString(page);
            System.out.println(pPageJson);

            byte[] pageJsontoBytes = pPageJson.getBytes();
            int resurt1 = LedControlInf.INSTANCE.LV_AddPageToProgram(screenNameToBytes, pProgramIdToBytes, pageJsontoBytes);

//         byte[] errByt = new byte[2048];
//         retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//
//         System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt1 == 0 ? "添加节目页面成功" : "添加节目页面失败");

            //*****************4、在节目页面上添加对应的显示区域*********************************************************

//         //图片区域
//         PictureArea a = new PictureArea();
//         a.setId(1);
//         a.setType(1);
//         a.setBorderEffect(0);
//         a.setBorderSW(0);
//         a.setBorderSpeed(0);
//         a.setBorderType(0);
//         a.setLeft(0);
//         a.setTop(0);
//         a.setWidth(256);
//         a.setHeight(192);
//         a.setPauseTime(5);
//         a.setRotation(0);
//         a.setSiderType(6);
//         List<SrcGroup> lsg = new ArrayList<SrcGroup>();
//         a.setSrcGroup(lsg);
//
//         SrcGroup s = new SrcGroup();
//         s.setId(1);
//         s.setSrc(src1);
//         a.getSrcGroup().add(s);
//
//         SrcGroup s1 = new SrcGroup();
//         s1.setId(2);
//         src1 = rootPath + "11.bmp";
//         s1.setSrc(src1);
//         a.getSrcGroup().add(s1);
//         a.setzIndex(0);
//
//         //对象转为Json
//         String ajson = mapper.writeValueAsString(a);
//
//         System.out.println(ajson);
//
//         byte[] ajsontobytes = ajson.getBytes();
////         int resurt2 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, ajsontobytes);
//         int resurt2 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes,pProgramIdToBytes, pageId, ajsontobytes);
////         retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
////         System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
//         System.out.println(resurt2 == 0 ? "添加图片区域成功" : "添加图片区域失败");


            //视频区域
            VideoArea videoArea = new VideoArea();
            videoArea.setId(3);
            videoArea.setType(0);
            videoArea.setBorderEffect(1);
            videoArea.setBorderSW(1);
            videoArea.setBorderSpeed(1);
            videoArea.setBorderType(9);
            videoArea.setLeft(0);
            videoArea.setTop(64);
            videoArea.setWidth(720);
            videoArea.setHeight(512);
            videoArea.setPauseTime(5);
            videoArea.setRotation(0);
            videoArea.setSiderType(6);
            List<SrcGroup> lsgVideoArea = new ArrayList<SrcGroup>();
            videoArea.setSrcGroup(lsgVideoArea);

            src1 = rootPath + "21.mp4";
            SrcGroup sVideoArea = new SrcGroup();
            sVideoArea.setId(1);
            sVideoArea.setSrc(src1);
            videoArea.getSrcGroup().add(sVideoArea);

            SrcGroup sVideoArea1 = new SrcGroup();
            sVideoArea1.setId(2);
            src1 = rootPath + "23.mp4";
            sVideoArea1.setSrc(src1);
            videoArea.getSrcGroup().add(sVideoArea1);

            SrcGroup sVideoArea2 = new SrcGroup();
            sVideoArea2.setId(3);
            src1 = rootPath + "yxceshi.mp4";
            sVideoArea2.setSrc(src1);
            videoArea.getSrcGroup().add(sVideoArea2);

            videoArea.setzIndex(0);

            //对象转为Json
            String vjson = mapper.writeValueAsString(videoArea);

            System.out.println(vjson);

            byte[] vjsontobytes = vjson.getBytes();
//         int resurt3 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, vjsontobytes);
            int resurt3 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes, pProgramIdToBytes, pageId, vjsontobytes);
//         retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//         System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt3 == 0 ? "添加视频区域成功" : "添加视频区域失败");


            //文本区域
            TextArea textArea = new TextArea();
            //id
            textArea.setId(2);
            //type Int 区域素材类型，字幕对应的类型为:2
            textArea.setType(2);
            //borderSW Int 区域边框开关 1:开 0:关
            textArea.setBorderSW(0);
            //borderEffect Int 区域边框特效 0:静止 1:旋转 2:闪烁
            textArea.setBorderEffect(0);
            //颜色特效 0:无 1:水平渐变 2:垂直渐变 3:斜角渐变
            textArea.setColorEffect(0);
            //borderSpeed int 区域边框速度 0~4
            textArea.setBorderSpeed(0);
            //borderType Int 区域边框类型 0~9 详见附录
            textArea.setBorderType(0);
            //left Int 区域 x 坐标点
            textArea.setLeft(0);
            //top Int 区域 y 坐标点
            textArea.setTop(0);
            //width Int 区域宽度
            textArea.setWidth(720);
            //height Int 区域高度
            textArea.setHeight(64);
            //background String 背景颜色,如:”#000000”,16 进制的 RRGGBB
            textArea.setBackground("#000000");
            //fontColor String 文字颜色, 如:”#ffffff”,16 进制的 RRGGBB
            textArea.setFontColor("#00ff00");
            //fontFamily String 文字字体,如”宋体”
            textArea.setFontFamily("宋体");
            //fontSize Int 字体大小 12~128 ,单位 px
            textArea.setFontSize(48);
            //italic Int 是否斜体 1:是 0:否
            textArea.setItalic(0);
            // bold Int 是否粗体 1:是 0:否
            textArea.setBold(1);
            //textLine Int 文字线 0:无 1:下划线 2:删除线
            textArea.setTextLine(0);
            //lineHeight Int 行间距,多行时有效
            textArea.setLineHeight(5);
            //pauseTime Int 停留时间,当字幕为向左向右平移时的停留时间,连续移 动无效 0~255
            textArea.setPauseTime(5);
            //scrollSpeed Int 字幕滚动速度 0~14
            textArea.setScrollSpeed(2);
            //siderType Int 滚动方式 0:静止 1:向左移动 2:向左连续移动 3:向右移动 4:向右连续移动
            textArea.setSiderType(2);
            //textAlign Int 对齐方式 0:左,1:中间 2:右
            textArea.setTextAlign(0);

            textArea.setTextTop(0);

            String strTextInfo = "AAAA灵信视觉二次开发动态库文本发送";
//         String base64Sign = base64.encodeToString(strTextInfo.getBytes("UTF-8"));
            textArea.setText(strTextInfo);
            //textShow Int 字幕显示方式 1:单行 0:多行
            textArea.setTextShow(1);
            //zIndex int 层级
            textArea.setzIndex(0);

            //对象转为Json
            String tjson = mapper.writeValueAsString(textArea);

            System.out.println(tjson);

            byte[] tjsontobytes = tjson.getBytes();
//        int resurt4 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, tjsontobytes);
            int resurt4 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes, pProgramIdToBytes, pageId, tjsontobytes);
//        retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//        System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt4 == 0 ? "添加文本区域成功" : "添加文本区域失败");

            //*****************5、发送节目内容*********************************************************

            //节目发送
//         retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(iptobytes);

            retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(screenNameToBytes, iptobytes, pProgramIdToBytes, pProgramNameToBytes, new byte[0]);
//         if(retValue != 0){
//            retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//            System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
//         }
            System.out.println(retValue == 0 ? "节目内容发送成功" : "节目内容发送失败");

            //*****************6、发送节目计划,执行播放节目指令 *********************************************************
            String pDefResVideoFile = "\0";

            List<ProgramPlan> lsProgram = new ArrayList<ProgramPlan>();

            ProgramPlan programPlan = new ProgramPlan();
            programPlan.setCreateDate(String.valueOf(new java.util.Date().getTime()));
            programPlan.setProgramId(pProgramId);
            programPlan.setProgramName(pProgramName);
            programPlan.setProgramType(2);//1:轮播节目(该类型节目最多只能1个) 2:插播节目 3:定时节目
            programPlan.setUpdateDate(String.valueOf(new java.util.Date().getTime()));

            //设置插播的日期范围与时间范围
            List<Date> lsDate = new ArrayList<Date>();
            SimpleDateFormat formatterDate = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            date.setDateStart(formatterDate.parse("2020-01-01").getTime());
            date.setDateEnd(formatterDate.parse("2022-12-31").getTime());
            lsDate.add(date);
            programPlan.setDate(lsDate);

            List<Time> lsTime = new ArrayList<Time>();

            SimpleDateFormat formatterTime = new SimpleDateFormat("yyyy-MM-dd");
//         Time time = new Time();
//         time.setTimeStart("08:30:00");
//         time.setTimeEnd("11:00:00");
//         lsTime.add(time);
//         Time time1 = new Time();
//         time1.setTimeStart("12:00:00");
//         time1.setTimeEnd("14:00:00");
//         lsTime.add(time1);
//         Time time2 = new Time();
//         time2.setTimeStart("16:00:00");
//         time2.setTimeEnd("17:00:00");
//         lsTime.add(time2);
            Time time3 = new Time();
            time3.setTimeStart("16:30:00");
            time3.setTimeEnd("23:59:59");
            lsTime.add(time3);
            programPlan.setTime(lsTime);

            programPlan.setIsDefault(0);
            List lsPlanWeekDay = new ArrayList();
            for (int i = 0; i < 7; i++) {
                lsPlanWeekDay.add(1);
            }
            programPlan.setPlanWeekDay(lsPlanWeekDay);
            lsProgram.add(programPlan);


            //对象转为Json
            String pPlanJsonData = mapper.writeValueAsString(lsProgram);
            System.out.println(pPlanJsonData);
            byte[] pPlanDatatobytes = pPlanJsonData.getBytes();

            if (retValue == 0) {
                retValue = LedControlInf.INSTANCE.LV_SendProgramPlan(iptobytes, pPlanDatatobytes, pDefResVideoFile.getBytes());
                System.out.println(retValue == 0 ? "节目更新计划发送成功" : "节目更新发送失败");
            }

            int retValue1 = LedControlInf.INSTANCE.LV_ProgramSendProcessEnd();
            System.out.println(retValue1 == 0 ? "节目缓存清理成功" : "节目缓存清理失败");
        } catch (JsonGenerationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            retValue = -1;
        } catch (JsonMappingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            retValue = -1;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            retValue = -1;
        }
        return retValue;
    }

    //多节目多页面-发送局部刷新的动态文本节目
    private static int btMulProgramByStaticText_Click(byte[] iptobytes) throws ParseException {

        String screenName1 = "test1";
        String pProgramId = "13";
        String pProgramName = "13";

        byte[] pProgramIdToBytes = (pProgramId + "\0").getBytes();
        byte[] pProgramNameToBytes = (pProgramName + "\0").getBytes();
        byte[] screenNameToBytes = (screenName1 + "\0").getBytes();

        String rootPath = System.getProperty("user.dir") + "\\resources\\";

        byte[] errByt = new byte[2048];
        int retValue = 0;

        try {

            retValue = LedControlInf.INSTANCE.LV_ClearProgram(screenNameToBytes);
            System.out.println("LV_ClearProgram = " + retValue);

            Random rd = new Random();
            int pageId = rd.nextInt(100);
            //直行
            String src1 = rootPath + "88.jpg";

            //*****************第一步 添加节目页面***********************************************************************
            Page page = new Page();
            page.setPageId(pageId);
            page.setResolution("1920X1080");
            page.setBgColor("#000000");
            page.setBgImg("");
            page.setEqType("Q5");
            page.setPageTime(10);
            UUID uuid = UUID.randomUUID();
            page.setGuid(uuid.toString());

            //对象转为Json
            ObjectMapper mapper = new ObjectMapper();
            String pPageJson = mapper.writeValueAsString(page);
            System.out.println(pPageJson);

            byte[] pageJsontoBytes = pPageJson.getBytes();
            int resurt1 = LedControlInf.INSTANCE.LV_AddPageToProgram(screenNameToBytes, pProgramIdToBytes, pageJsontoBytes);

//         byte[] errByt = new byte[2048];
//         retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//
//         System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt1 == 0 ? "添加节目页面成功" : "添加节目页面失败");

            //*****************第二步 在节目页面上添加对应的显示区域*********************************************************

//         //图片区域
//         PictureArea a = new PictureArea();
//         a.setId(1);
//         a.setType(1);
//         a.setBorderEffect(0);
//         a.setBorderSW(0);
//         a.setBorderSpeed(0);
//         a.setBorderType(0);
//         a.setLeft(0);
//         a.setTop(0);
//         a.setWidth(128);
//         a.setHeight(128);
//         a.setPauseTime(5);
//         a.setRotation(0);
//         a.setSiderType(6);
//         List<SrcGroup> lsg = new ArrayList<SrcGroup>();
//         a.setSrcGroup(lsg);
//
//         SrcGroup s = new SrcGroup();
//         s.setId(1);
//         s.setSrc(src1);
//         a.getSrcGroup().add(s);
//
//         SrcGroup s1 = new SrcGroup();
//         s1.setId(2);
//         src1 = rootPath + "83.jpg";
//         s1.setSrc(src1);
//         a.getSrcGroup().add(s1);
//         a.setzIndex(0);
//
//         //对象转为Json
//         String ajson = mapper.writeValueAsString(a);
//
//         System.out.println(ajson);
//
//         byte[] ajsontobytes = ajson.getBytes();
////         int resurt2 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, ajsontobytes);
//         int resurt2 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes,pProgramIdToBytes, pageId, ajsontobytes);
////         retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
////         System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
//         System.out.println(resurt2 == 0 ? "添加图片区域成功" : "添加图片区域失败");


            //视频区域
            VideoArea videoArea = new VideoArea();
            videoArea.setId(3);
            videoArea.setType(0);
            videoArea.setBorderEffect(1);
            videoArea.setBorderSW(1);
            videoArea.setBorderSpeed(1);
            videoArea.setBorderType(9);
            videoArea.setLeft(0);
            videoArea.setTop(64);
            videoArea.setWidth(256);
            videoArea.setHeight(96);
            videoArea.setPauseTime(5);
            videoArea.setRotation(0);
            videoArea.setSiderType(6);
            List<SrcGroup> lsgVideoArea = new ArrayList<SrcGroup>();
            videoArea.setSrcGroup(lsgVideoArea);

            src1 = rootPath + "21.mp4";
            SrcGroup sVideoArea = new SrcGroup();
            sVideoArea.setId(1);
            sVideoArea.setSrc(src1);
            videoArea.getSrcGroup().add(sVideoArea);

            SrcGroup sVideoArea1 = new SrcGroup();
            sVideoArea1.setId(2);
            src1 = rootPath + "23.mp4";
            sVideoArea1.setSrc(src1);
            videoArea.getSrcGroup().add(sVideoArea1);
            videoArea.setzIndex(0);

            //对象转为Json
            String vjson = mapper.writeValueAsString(videoArea);

            System.out.println(vjson);

            byte[] vjsontobytes = vjson.getBytes();
//         int resurt3 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, vjsontobytes);
            int resurt3 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes, pProgramIdToBytes, pageId, vjsontobytes);
//         retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//         System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt3 == 0 ? "添加视频区域成功" : "添加视频区域失败");


            //静态刷新文本区域
            TextArea textArea = new TextArea();
            //id
            textArea.setId(2);
            //type Int 区域素材类型，字幕对应的类型为:2
            textArea.setType(200);
            //borderSW Int 区域边框开关 1:开 0:关
            textArea.setBorderSW(0);
            //borderEffect Int 区域边框特效 0:静止 1:旋转 2:闪烁
            textArea.setBorderEffect(0);
            //borderSpeed int 区域边框速度 0~4
            textArea.setBorderSpeed(0);
            //borderType Int 区域边框类型 0~9 详见附录
            textArea.setBorderType(0);
            //left Int 区域 x 坐标点
            textArea.setLeft(5);
            //top Int 区域 y 坐标点
            textArea.setTop(0);
            //width Int 区域宽度
            textArea.setWidth(256);
            //height Int 区域高度
            textArea.setHeight(32);
            //background String 背景颜色,如:”#000000”,16 进制的 RRGGBB
            textArea.setBackground("#000000");
            //fontColor String 文字颜色, 如:”#ffffff”,16 进制的 RRGGBB
            textArea.setFontColor("#00ff00");
            //fontFamily String 文字字体,如”宋体”
            textArea.setFontFamily("宋体");
            //fontSize Int 字体大小 12~128 ,单位 px
            textArea.setFontSize(12);
            //italic Int 是否斜体 1:是 0:否
            textArea.setItalic(0);
            // bold Int 是否粗体 1:是 0:否
            textArea.setBold(1);
            //textLine Int 文字线 0:无 1:下划线 2:删除线
            textArea.setTextLine(0);
            //pauseTime Int 停留时间,当字幕为向左向右平移时的停留时间,连续移 动无效 0~255
            textArea.setPauseTime(5);
            //scrollSpeed Int 字幕滚动速度 0~14
            textArea.setScrollSpeed(2);
            //siderType Int 滚动方式 0:静止 1:向左移动 3:向右移动 5:上移 7:下移
            textArea.setSiderType(2);
            //textAlign Int 对齐方式 0:左,1:中间 2:右
            textArea.setTextAlign(0);

            //textAlign Int 对齐方式 0:左,1:中间 2:右
            textArea.setvTextAlign(0);

            String strTextInfo = "1号静态文本区域";
//         String base64Sign = base64.encodeToString(strTextInfo.getBytes("UTF-8"));
            textArea.setText(strTextInfo);

            //显示数据是否为 base64 编码 0:否 1:是
            textArea.setBase64(0);

            //zIndex int 层级
            textArea.setzIndex(0);

            //对象转为Json
            String tjson = mapper.writeValueAsString(textArea);

            System.out.println(tjson);

            byte[] tjsontobytes = tjson.getBytes();
//        int resurt4 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, tjsontobytes);
            int resurt4 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes, pProgramIdToBytes, pageId, tjsontobytes);
//        retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//        System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt4 == 0 ? "添加静态文本区域成功" : "添加静态文本区域失败");


            //静态刷新文本区域
            TextArea textArea1 = new TextArea();
            //id
            textArea1.setId(20);
            //type Int 区域素材类型，字幕对应的类型为:2
            textArea1.setType(200);
            //borderSW Int 区域边框开关 1:开 0:关
            textArea1.setBorderSW(0);
            //borderEffect Int 区域边框特效 0:静止 1:旋转 2:闪烁
            textArea1.setBorderEffect(0);
            //borderSpeed int 区域边框速度 0~4
            textArea1.setBorderSpeed(0);
            //borderType Int 区域边框类型 0~9 详见附录
            textArea1.setBorderType(0);
            //left Int 区域 x 坐标点
            textArea1.setLeft(5);
            //top Int 区域 y 坐标点
            textArea1.setTop(32);
            //width Int 区域宽度
            textArea1.setWidth(256);
            //height Int 区域高度
            textArea1.setHeight(32);
            //background String 背景颜色,如:”#000000”,16 进制的 RRGGBB
            textArea1.setBackground("#000000");
            //fontColor String 文字颜色, 如:”#ffffff”,16 进制的 RRGGBB
            textArea1.setFontColor("#00ff00");
            //fontFamily String 文字字体,如”宋体”
            textArea1.setFontFamily("宋体");
            //fontSize Int 字体大小 12~128 ,单位 px
            textArea1.setFontSize(12);
            //italic Int 是否斜体 1:是 0:否
            textArea1.setItalic(0);
            // bold Int 是否粗体 1:是 0:否
            textArea1.setBold(1);
            //textLine Int 文字线 0:无 1:下划线 2:删除线
            textArea1.setTextLine(0);
            //pauseTime Int 停留时间,当字幕为向左向右平移时的停留时间,连续移 动无效 0~255
            textArea1.setPauseTime(5);
            //scrollSpeed Int 字幕滚动速度 0~14
            textArea1.setScrollSpeed(2);
            //siderType Int 滚动方式 0:静止 1:向左移动 3:向右移动 5:上移 7:下移
            textArea1.setSiderType(2);
            //textAlign Int 对齐方式 0:左,1:中间 2:右
            textArea1.setTextAlign(0);

            //textAlign Int 对齐方式 0:左,1:中间 2:右
            textArea1.setvTextAlign(0);

            strTextInfo = "2号静态文本区域";
//         String base64Sign = base64.encodeToString(strTextInfo.getBytes("UTF-8"));
            textArea1.setText(strTextInfo);

            //显示数据是否为 base64 编码 0:否 1:是
            textArea1.setBase64(0);

            //zIndex int 层级
            textArea1.setzIndex(0);

            //对象转为Json
            tjson = mapper.writeValueAsString(textArea1);

            System.out.println(tjson);

            tjsontobytes = tjson.getBytes();
//        int resurt4 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, tjsontobytes);
            resurt4 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes, pProgramIdToBytes, pageId, tjsontobytes);
//        retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//        System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt4 == 0 ? "添加静态文本区域成功" : "添加静态文本区域失败");

            //*****************第三步 发送节目内容*********************************************************

            //节目发送
//         retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(iptobytes);

            retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(screenNameToBytes, iptobytes, pProgramIdToBytes, pProgramNameToBytes, new byte[0]);
//         if(retValue != 0){
//            retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//            System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
//         }
            System.out.println(retValue == 0 ? "节目内容发送成功" : "节目内容发送失败");

            //*****************第四步 发送节目计划,执行播放节目指令 *********************************************************
            String pDefResVideoFile = "\0";

//         MulProgram mulProgram = new MulProgram();


            List<ProgramPlan> lsProgram = new ArrayList<ProgramPlan>();

            ProgramPlan programPlan = new ProgramPlan();
            programPlan.setCreateDate(String.valueOf(new java.util.Date().getTime()));
            programPlan.setProgramId(pProgramId);
            programPlan.setProgramName(pProgramName);
            programPlan.setProgramType(1);//1标识为轮播节目
            programPlan.setUpdateDate(String.valueOf(new java.util.Date().getTime()));

            List<Date> lsDate = new ArrayList<Date>();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            date.setDateStart(formatter.parse("2020-03-30").getTime());
            date.setDateEnd(formatter.parse("2020-04-30").getTime());
            lsDate.add(date);
            programPlan.setDate(lsDate);

            List<Time> lsTime = new ArrayList<Time>();
            Time time = new Time();
            time.setTimeStart("07:59:59");
            time.setTimeEnd("21:59:59");
            lsTime.add(time);
            programPlan.setTime(lsTime);

            programPlan.setIsDefault(1);
            List lsPlanWeekDay = new ArrayList();
            for (int i = 0; i < 7; i++) {
                lsPlanWeekDay.add(1);
            }
            programPlan.setPlanWeekDay(lsPlanWeekDay);
            lsProgram.add(programPlan);

//         mulProgram.setProgram(lsProgram);

            //对象转为Json
            String pPlanJsonData = mapper.writeValueAsString(lsProgram);
            System.out.println(pPlanJsonData);
            byte[] pPlanDatatobytes = pPlanJsonData.getBytes();

            if (retValue == 0) {
                retValue = LedControlInf.INSTANCE.LV_SendProgramPlan(iptobytes, pPlanDatatobytes, pDefResVideoFile.getBytes());
                System.out.println(retValue == 0 ? "节目更新计划发送成功" : "节目更新发送失败");
            }

            int retValue1 = LedControlInf.INSTANCE.LV_ProgramSendProcessEnd();
            System.out.println(retValue1 == 0 ? "节目缓存清理成功" : "节目缓存清理失败");
        } catch (JsonGenerationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            retValue = -1;
        } catch (JsonMappingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            retValue = -1;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            retValue = -1;
        }
        return retValue;
    }

    //多节目多页面-发送局部刷新的动态图片节目
    private static int btMulProgramByStaticPicture_Click(byte[] iptobytes) throws ParseException {

        String screenName1 = "test1";
        String pProgramId = "13";
        String pProgramName = "13";

        byte[] pProgramIdToBytes = (pProgramId + "\0").getBytes();
        byte[] pProgramNameToBytes = (pProgramName + "\0").getBytes();
        byte[] screenNameToBytes = (screenName1 + "\0").getBytes();

        String rootPath = System.getProperty("user.dir") + "\\resources\\";

        byte[] errByt = new byte[2048];
        int retValue = 0;

        try {

            retValue = LedControlInf.INSTANCE.LV_ClearProgram(screenNameToBytes);
            System.out.println("LV_ClearProgram = " + retValue);

            int pageId = 1;
            //直行
            String src1 = rootPath + "88.jpg";

            //*****************第一步 添加节目页面***********************************************************************
            Page page = new Page();
            page.setPageId(pageId);
            page.setResolution("1920X1080");
            page.setBgColor("#000000");
            page.setBgImg("");
            page.setEqType("Q5");
            page.setPageTime(10);
            UUID uuid = UUID.randomUUID();
            page.setGuid(uuid.toString());

            //对象转为Json
            ObjectMapper mapper = new ObjectMapper();
            String pPageJson = mapper.writeValueAsString(page);
            System.out.println(pPageJson);

            byte[] pageJsontoBytes = pPageJson.getBytes();
            int resurt1 = LedControlInf.INSTANCE.LV_AddPageToProgram(screenNameToBytes, pProgramIdToBytes, pageJsontoBytes);

//         byte[] errByt = new byte[2048];
//         retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//
//         System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt1 == 0 ? "添加节目页面成功" : "添加节目页面失败");

            //*****************第二步 在节目页面上添加对应的显示区域*********************************************************

            //图片区域
            PictureArea a = new PictureArea();
            a.setId(1);
            a.setType(204);
            a.setBorderEffect(0);
            a.setBorderSW(0);
            a.setBorderSpeed(0);
            a.setBorderType(0);
            a.setLeft(0);
            a.setTop(0);
            a.setWidth(128);
            a.setHeight(128);
            a.setPauseTime(5);
            a.setRotation(0);
            a.setSiderType(6);
            List<SrcGroup> lsg = new ArrayList<SrcGroup>();
            a.setSrcGroup(lsg);

            SrcGroup s = new SrcGroup();
            s.setId(1);
            s.setSrc(src1);
            a.getSrcGroup().add(s);

            SrcGroup s1 = new SrcGroup();
            s1.setId(2);
            src1 = rootPath + "83.jpg";
            s1.setSrc(src1);
            a.getSrcGroup().add(s1);
            a.setzIndex(0);

            //对象转为Json
            String ajson = mapper.writeValueAsString(a);

            System.out.println(ajson);

            byte[] ajsontobytes = ajson.getBytes();
//         int resurt2 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, ajsontobytes);
            int resurt2 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes, pProgramIdToBytes, pageId, ajsontobytes);
//         retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//         System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt2 == 0 ? "添加图片区域成功" : "添加图片区域失败");

            //文本区域
            TextArea textArea = new TextArea();
            //id
            textArea.setId(2);
            //type Int 区域素材类型，字幕对应的类型为:2
            textArea.setType(2);
            //borderSW Int 区域边框开关 1:开 0:关
            textArea.setBorderSW(0);
            //borderEffect Int 区域边框特效 0:静止 1:旋转 2:闪烁
            textArea.setBorderEffect(0);
            //颜色特效 0:无 1:水平渐变 2:垂直渐变 3:斜角渐变
            textArea.setColorEffect(0);
            //borderSpeed int 区域边框速度 0~4
            textArea.setBorderSpeed(0);
            //borderType Int 区域边框类型 0~9 详见附录
            textArea.setBorderType(0);
            //left Int 区域 x 坐标点
            textArea.setLeft(5);
            //top Int 区域 y 坐标点
            textArea.setTop(128);
            //width Int 区域宽度
            textArea.setWidth(256);
            //height Int 区域高度
            textArea.setHeight(64);
            //background String 背景颜色,如:”#000000”,16 进制的 RRGGBB
            textArea.setBackground("#000000");
            //fontColor String 文字颜色, 如:”#ffffff”,16 进制的 RRGGBB
            textArea.setFontColor("#00ff00");
            //fontFamily String 文字字体,如”宋体”
            textArea.setFontFamily("宋体");
            //fontSize Int 字体大小 12~128 ,单位 px
            textArea.setFontSize(48);
            //italic Int 是否斜体 1:是 0:否
            textArea.setItalic(0);
            // bold Int 是否粗体 1:是 0:否
            textArea.setBold(1);
            //textLine Int 文字线 0:无 1:下划线 2:删除线
            textArea.setTextLine(0);
            //lineHeight Int 行间距,多行时有效
            textArea.setLineHeight(5);
            //pauseTime Int 停留时间,当字幕为向左向右平移时的停留时间,连续移 动无效 0~255
            textArea.setPauseTime(5);
            //scrollSpeed Int 字幕滚动速度 0~14
            textArea.setScrollSpeed(2);
            //siderType Int 滚动方式 0:静止 1:向左移动 2:向左连续移动 3:向右移动 4:向右连续移动
            textArea.setSiderType(2);
            //textAlign Int 对齐方式 0:左,1:中间 2:右
            textArea.setTextAlign(0);
            textArea.setTextTop(0);

            String strTextInfo = "异步全彩字幕演示测试，上海灵信视觉技术股份有限公司提供！！！";
//         String base64Sign = base64.encodeToString(strTextInfo.getBytes("UTF-8"));
            textArea.setText(strTextInfo);
            //textShow Int 字幕显示方式 1:单行 0:多行
            textArea.setTextShow(1);
            //zIndex int 层级
            textArea.setzIndex(0);

            //对象转为Json
            String tjson = mapper.writeValueAsString(textArea);

            System.out.println(tjson);

            byte[] tjsontobytes = tjson.getBytes();
//        int resurt4 = LedControlInf.INSTANCE.LV_AddArea(iptobytes, pid, tjsontobytes);
            int resurt4 = LedControlInf.INSTANCE.LV_AddArea(screenNameToBytes, pProgramIdToBytes, pageId, tjsontobytes);
//        retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//        System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
            System.out.println(resurt4 == 0 ? "添加文本区域成功" : "添加文本区域失败");

            //*****************第三步 发送节目内容*********************************************************

            //节目发送
//         retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(iptobytes);

            retValue = LedControlInf.INSTANCE.LV_SendProgramToDevice(screenNameToBytes, iptobytes, pProgramIdToBytes, pProgramNameToBytes, new byte[0]);
//         if(retValue != 0){
//            retValue = LedControlInf.INSTANCE.LV_GetLastErrInfo(errByt, errByt.length);
//            System.out.println(new String(new String(errByt).getBytes("ISO8859_1"),"UTF-8"));
//         }
            System.out.println(retValue == 0 ? "节目内容发送成功" : "节目内容发送失败");

            //*****************第四步 发送节目计划,执行播放节目指令 *********************************************************
            String pDefResVideoFile = "\0";

//         MulProgram mulProgram = new MulProgram();


            List<ProgramPlan> lsProgram = new ArrayList<ProgramPlan>();

            ProgramPlan programPlan = new ProgramPlan();
            programPlan.setCreateDate(String.valueOf(new java.util.Date().getTime()));
            programPlan.setProgramId(pProgramId);
            programPlan.setProgramName(pProgramName);
            programPlan.setProgramType(1);//1标识为轮播节目
            programPlan.setUpdateDate(String.valueOf(new java.util.Date().getTime()));

            List<Date> lsDate = new ArrayList<Date>();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            date.setDateStart(formatter.parse("2020-03-30").getTime());
            date.setDateEnd(formatter.parse("2020-04-30").getTime());
            lsDate.add(date);
            programPlan.setDate(lsDate);

            List<Time> lsTime = new ArrayList<Time>();
            Time time = new Time();
            time.setTimeStart("07:59:59");
            time.setTimeEnd("21:59:59");
            lsTime.add(time);
            programPlan.setTime(lsTime);

            programPlan.setIsDefault(1);
            List lsPlanWeekDay = new ArrayList();
            for (int i = 0; i < 7; i++) {
                lsPlanWeekDay.add(1);
            }
            programPlan.setPlanWeekDay(lsPlanWeekDay);
            lsProgram.add(programPlan);

//         mulProgram.setProgram(lsProgram);

            //对象转为Json
            String pPlanJsonData = mapper.writeValueAsString(lsProgram);
            System.out.println(pPlanJsonData);
            byte[] pPlanDatatobytes = pPlanJsonData.getBytes();

            if (retValue == 0) {
                retValue = LedControlInf.INSTANCE.LV_SendProgramPlan(iptobytes, pPlanDatatobytes, pDefResVideoFile.getBytes());
                System.out.println(retValue == 0 ? "节目更新计划发送成功" : "节目更新发送失败");
            }

            int retValue1 = LedControlInf.INSTANCE.LV_ProgramSendProcessEnd();
            System.out.println(retValue1 == 0 ? "节目缓存清理成功" : "节目缓存清理失败");
        } catch (JsonGenerationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            retValue = -1;
        } catch (JsonMappingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            retValue = -1;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            retValue = -1;
        }
        return retValue;
    }
}
